<?php
namespace app\admin\model;

use think\Model;

class Banner extends Model
{   
	/*查询数据 */
	public function get_data(){
        $data=Banner::where([['status','=',1]])->select()->order('create_time','desc');
        return $data;
	}
	/*新增*/
	public function insert_data($alt,$newname,$type){
        $Banner = new Banner;
		$result=$Banner->save([
		    'alt'  =>  trim($alt),
		    'img' =>  trim($newname),
		    'type' =>  trim($type),
		    'create_time'=> date('Y-m-d H:i:s',time())
		]);
		return $result;
	}
	/*修改*/
	public function update_data($id,$alt,$newname,$type){
        $data = Banner::get($id);
        $data->alt = trim($alt);
        $data->img = trim($newname);
        $data->type = trim($type);
        $result=$data->save();
		return $result;    
	}
	/*删除假动作实际为修改操作*/
	public function delete_data($id){
        $data = Banner::get($id);
        if($data['status']!=1){
        	$result=['status'=>'0','msg'=>'无需操作'];
	        return json($result);
        }
		$data->status = '2';
		$result=$data->save();
		return $result;
	}
}
 